<?php
/**
 * Created by PhpStorm.
 * User: jhon
 * Date: 2018/2/9
 * Time: 9:38
 */

namespace app\admin\controller;
use think\Request;
use think\Db;

class Customer extends Auto
{

    public function index(){
        $result  = Db::table('organization')->select();
        $this->assign('org_list',$result);
        return $this->fetch();
    }

    //    客户查询
    public function customerquery(){
        $result  = Db::table('customer')
            ->where('org_code',session('user.org_code'))
            ->select();
        $dataarr = [
            'data'=>$result
        ];
        echo json_encode($dataarr);
    }

    //    删除客户
    public function customerdel(){
        $Request = Request::instance();
        $param = $Request->param();
        $ID = $param['ID'];
        $result  = Db::table('user_acc')->delete($ID);
        echo $result;
    }

    //    修改客户
    public function customerupd(){
        $Request = Request::instance();
        $param = $Request->param();
        $acc_pwd = $param['acc_pwd'];
        $acc_name = $param['acc_name'];
        $data = [
            'acc_pwd' =>md5($acc_pwd),
        ];
        $result  = Db::table('user_acc')->where('acc_name',$acc_name)->update($data);
        echo $result;

    }

    //    添加客户
    public function customeradd(){

        $Request = Request::instance();
        $param = $Request->param();
        $data=[
            'cust_name'=>'test',
            'sex'=>'1',
            'birth_year'=>'2000',
            'height'=>'168',
            'weight'=>'50',
            'mobile'=>'18888888888',
            'train_target'=>'增肌',
            'org_code'=>'ORG_5a7d07831cca6',
            'mark'=>'1',
            'create_date'=>date('Y-m-d H:i:s',time()),
        ];
        $result  = Db::table('customer')->insert($data);
        echo $result;
    }


}